package Test5;

public class ArrayReverser {
    private int[] array;
    public ArrayReverser(int[] array) throws IllegalArgumentException {
        if (array == null ) {
            throw new IllegalArgumentException("illegal array");
        }
        this.array = array;
    }
    public ArrayReverser() throws IllegalArgumentException {
        this(new int[0]);
    }

    public int[] getArray() {
        return array;
    }

    public void setArray(int[] array) {
        this.array = array;
    }
    public void reverse() {
        for (int i = 0; i < array.length / 2; i++) {
            int temp = array[i];
            array[i] = array[array.length - i - 1];
            array[array.length - i - 1] = temp;
        }
    }
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof ArrayReverser obj1) {
            if (array.length != obj1.array.length) {
                return false;
            }
            for (int i = 0; i < array.length; i++) {
                if (array[i] != obj1.array[i]) {
                    return false;
                }
            }
            return true;
        }else
            return false;
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (int i : array) {
            sb.append(i).append(" ");
        }
        return sb.toString();
    }


}
